package com.app.xinfadi.ui.purchase_plan.center_purchase_plan;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.app.xinfadi.R;
import com.app.xinfadi.base.BaseActivity;
import com.app.xinfadi.ui.purchase_plan.center_purchase_plan.new_bill_of_sales_status.NewBillOfSalesFinishFragment;
import com.app.xinfadi.ui.purchase_plan.center_purchase_plan.new_bill_of_sales_status.NewBillOfSalesNotFinishFragment;
import com.app.xinfadi.ui.purchase_plan.center_purchase_plan.new_bill_of_sales_status.NewBillOfSalesPartFinishFragment;
import com.sevenheaven.segmentcontrol.SegmentControl;

import java.util.ArrayList;

/**
 * function: 登出出货表
 * Created by Wutengfei on 2016/1/25.
 */
public class NewBillOfSalesBtnActivity extends BaseActivity {
    private ViewPager mViewPager;
    private ArrayList<Fragment> waitDealingFragmentList;
    private FragmentPagerAdapter mAdapter;
    private ViewPager.OnPageChangeListener mPagerChangeListener;
    private SegmentControl segment_control;
    private String[] status = {"03", "04", "05"};
    private String plan_id;
    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.new_bill_of_sales_layout_activity);
        plan_id = getIntent().getStringExtra("plan_id");
        initToolbar();
        initView();

    }

    private void initToolbar() {
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mToolbar.setTitle("");
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        TextView title = (TextView) findViewById(R.id.titleTv);
        title.setVisibility(View.VISIBLE);
        title.setText("出货登记单");
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    private void initView() {
        mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
        mViewPager.setOffscreenPageLimit(3);

        waitDealingFragmentList = new ArrayList<>();
        waitDealingFragmentList.add(NewBillOfSalesFinishFragment.getInstance(plan_id));
        waitDealingFragmentList.add(NewBillOfSalesPartFinishFragment.getInstance(plan_id));
        waitDealingFragmentList.add(NewBillOfSalesNotFinishFragment.getInstance(plan_id));

        mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

            @Override
            public int getCount() {
                return waitDealingFragmentList.size();
            }

            @Override
            public Fragment getItem(int arg0) {
                return waitDealingFragmentList.get(arg0);
            }
        };

        mViewPager.setAdapter(mAdapter);
        mPagerChangeListener = new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                segment_control.setSelectedIndex(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        };
        mViewPager.addOnPageChangeListener(mPagerChangeListener);

        segment_control = (SegmentControl) findViewById(R.id.segment_control);
        segment_control.setOnSegmentControlClickListener(new SegmentControl.OnSegmentControlClickListener() {
            @Override
            public void onSegmentControlClick(int index) {
                mViewPager.setCurrentItem(index);
                ((NewBillOfSalesFinishFragment) waitDealingFragmentList.get(0)).setIsUploading(false);
                ((NewBillOfSalesPartFinishFragment) waitDealingFragmentList.get(1)).setIsUploading(false);

                switch (index) {
                    case 0:
                        break;
                    case 1:

                        break;
                    case 2:

                        break;

                }
//                mViewPager.setCurrentItem(index);
            }
        });
    }

}
